package aleetcode;

public class _5
{public static void main(String[] args) {
    String s="(){}[]";
    boolean valid = isValid(s);
    if(valid){
        System.out.println("合法");
    }else {
        System.out.println("不合法");
    }
}
    public static boolean isValid(String s) {
        int len=s.length()/2;
        for(int i=0;i<len;i++)
            s = s.replace("()", "").replace("[]", "").replace("{}", "");
        return s.length() == 0;
    }
}
